var app = getApp(),
  that;

Page({
  data: {
    open: 1,
    kong: !0,
    vipLevelInfo: {},
    bizUserInfo: {},
    addInfo: {},
    czje: '',
    topActiv: [],
    page: 1,
    rows: 10,
    currentTab: '',
    inputValue: '',
    isDisabled: false,
    itemActivity: null
  },
  onLoad: function(t) {
    that = this
    var e = this,
      a = getApp().imgurl,
      o = wx.getStorageSync("mdid");
    console.log(o);
    e.setData({
      bizUserInfo: wx.getStorageSync("bizUserInfo"),
      vipLevelInfo: wx.getStorageSync("vipLevelInfo"),
      addInfo: app.globalData.shopData
    })
    
  },
  jsmj: function(t, e) {
    for (var a, o = 0; o < e.length; o++)
      if (Number(t) >= Number(e[o].full)) {
        a = o;
        break;
      }
    return a;
  },
  bindInput: function(t) {
    console.log(t.detail.value),
      this.setData({
        czje: t.detail.value
      }),
      "" != t.detail.value ? this.setData({
        kong: !1,
      }) : this.setData({
        kong: !0,
      });
  },
  tradeinfo: function() {
    this.setData({
      open: !this.data.open
    });
  },
  tijiao: function() {
    wx.showToast({
      title: '请注册会员',
      duration: 2000
    })
  },
  formSubmit: function(t) {
    console.log(t);
    console.log(that.data.itemActivity ? that.data.itemActivity.giveAmt : 0)
    app.getData({
      url: app.api.getBalance(),
      method: "POST",
      data: {
        memberId: wx.getStorageSync('bizUserInfo').id,
        payType: 1,
        rechargeAmt: that.data.itemActivity ? that.data.itemActivity.rechargeAmt : t.detail.value.czje,
        giveAmt: that.data.itemActivity ? that.data.itemActivity.giveAmt : 0,
        rechargeType: 1,
        companyId: app.globalData.companyId,
      },
      ok: function(t) {
        console.log(t)
        //  添加订单成功之后去支付
        var openId = wx.getStorageSync("openId")
        // var openId = "wxd2188c60cd7f825f";
        app.getData({
          url: app.api.toPay(t.data.data.id, openId, 2), //仅为示例，并非真实的接口地址
          method: 'GET',
          ok: function(e) {
            console.log(e)
            wx.requestPayment({
              timeStamp: JSON.stringify((JSON.parse(e.data.params)).timeStamp),
              nonceStr: (JSON.parse(e.data.params)).nonceStr,
              package: (JSON.parse(e.data.params)).package,
              signType: 'MD5',
              paySign: (JSON.parse(e.data.params)).paySign,
              success: function(t) {
                wx.navigateTo({
                  url: '../../../../../../mine/pages/wdzd/wdzd'
                })
                that.getBizUserInfo()
              },
              fail: function(t) {
                console.log(t)
                wx.showToast({
                  title: '充值失败',
                  duration: 3000
                })
              },
              complete: function(t) {}
            })
          }
        })
      }
    })
  },
  getBizUserInfo: function () {
    var that = this
    app.getData({
      url: app.api.getBizUserInfo(),
      data: {
        openid: wx.getStorageSync('openId')
      },
      ok: function (res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            wx.setStorageSync('bizUserInfo', res.data.data)
          }
        }
      }
    })
  },
  topActiv: function(t) {
    console.log(t)
    if (t.currentTarget.dataset.item.id === this.data.currentTab) {
      this.setData({
        currentTab: 'BB',
        inputValue: '',
        isDisabled: false,
        itemActivity: null,
        kong: !0
      });
    } else {
      this.setData({
        currentTab: t.currentTarget.dataset.item.id,
        inputValue: t.currentTarget.dataset.item.rechargeAmt,
        isDisabled: true,
        itemActivity: t.currentTarget.dataset.item,
        kong: !1
      });
    }
  },

  onReady: function() {},
  onShow: function() {
    app.getData({
      url: app.api.getTopActiv(1, 10),
      method: 'GET',
      ok: function(res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            that.setData({
              topActiv: res.data.list
            })
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }

    });

  },
  onHide: function() {},
  onUnload: function() {},
  onReachBottom: function() {},

})